<template>
	<view>
		<!-- <hx-navbar  :is-back="false" ref="hxnb" :config="config" /> -->
		<u-navbar :is-back="false" title-color="#333" title-bold title-size="36" title="AI大模型" :border-bottom="false"></u-navbar>
		
		
		<!-- <view class="">
			<button @click="toAI">进入AI聊天</button>
		</view> -->
		
		<view class="from-text">
			<view class="qd-btn" @click="todetail(-1)">
				新建对话
			</view>
			<view class="form-title">
				历史对话
			</view>
			<view class="">
				<view class="ai-list flex flex_sb" v-for="(item,index) in duihuaList" :key="index">
					<view class="flex" @click="todetail(item)">
						<view class="aiti line_1 u-m-l-20">
							{{item.title}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-tabbar active-color="#FA3B21" :list="tabbar" :mid-button="true"></u-tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo:[],
				tabbar: '',
				duihuaList:[],
				config: {
					statusBarBackground: '#fff',
					title: 'AI大模型',
				},
			}
		},
		onLoad() {
			this.tabbar = [{
					iconPath: "/static/img/tabBar/1-2.png",
					selectedIconPath: "/static/img/tabBar/1-1.png",
					text: '首页',
					pagePath: "/pages/index/index"
				},{
					iconPath: "/static/img/tabBar/2-2.png",
					selectedIconPath: "/static/img/tabBar/2-1.png",
					text: '找律师',
					pagePath: "/pages/lawyer/lawyer"
				},{
					iconPath: "/static/img/tabBar/3-1.png",
					selectedIconPath: "/static/img/tabBar/3-1.png",
					text: 'AI模型',
					midButton: true,
					pagePath: "/pages/AI/AI"
				},{
					iconPath: "/static/img/tabBar/4-1.png",
					selectedIconPath: "/static/img/tabBar/4-1.png",
					text: '在线咨询',
					// count: 2,
					isDot: false,
					pagePath: "/TXIM/pages/consultation/consultation"
				},{
					iconPath: "/static/img/tabBar/5-2.png",
					selectedIconPath: "/static/img/tabBar/5-1.png",
					text: '我的',
					pagePath: "/pages/mine/mine"
				},
				
			]
			this.getAiDiaLogList()
			this.getInfo()
		},
		
		
		methods: {
			//个人信息
			getInfo() {
				this.$api({
					url: '/getUserInfo',
					method: 'get',
					data: {
						token:uni.getStorageSync("token")
					},
				}).then(res => {
					if (res.code == 1) {
						this.userInfo = res.data
					}
				})
			},
			getAiDiaLogList() {
				this.$api({
					url: '/user/getAiDiaLogList',
					method: 'post',
					data: {
						token: uni.getStorageSync("token")
					},
				}).then(res => {
					if (res.code == 1) {
						this.duihuaList = res.data.list
					}
				})
			},
			del(e) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确认删除吗',
					success: function(res) {
						if (res.confirm) {
							that.$api({
								url: '/user/deleteAiDialog',
								method: 'post',
								data: {
									token: uni.getStorageSync("token"),
									dialog_id: e.id
								},
							}).then(res => {
								if (res.code == 1) {
									that.getAiDiaLogList()
								}
							})
						}
					}
				});
			
			
			
			},
			
			todetail(e){
				if(this.userInfo.ai_assistant==1){
					if(e==-1){
						uni.navigateTo({
							url:"/subPackageA/pages/AI/AIcaht"
						})
					}else{
						uni.navigateTo({
							url:"/subPackageA/pages/AI/AIcaht?id="+e.id
						})
					}
				}else{
					uni.showModal({
						title: '提示',
						content: 'AI助手已过期，请购买',
						success: function(res) {
							if (res.confirm) {
								uni.navigateTo({
									url: "/pages/mine/AIpay"
								})
							}
						}
					});
					// uni.showToast({
					// 	title: "AI助手已过期，请购买",
					// 	icon: "none"
					// });
					// uni.navigateTo({
					// 	url: "/pages/mine/AIpay"
					// })
					
				}
				
			}
		}
	}
</script>

<style scoped lang="scss">
	.from-text {
		/* position: relative; */
		width: 640rpx;
		padding: 0 30rpx;
		padding-top: 20rpx;
		position: relative;
		
	
		.form-title {
			font-size: 32rpx;
			color: #222222;
			margin-top: 60rpx;
		}
	
		.ai-list {
			padding: 30rpx;
	
			.aidh {
				width: 24rpx;
				height: 20rpx;
			}
	
			.aiti {
				font-size: 28rpx;
				color: #333333;
				width: 600rpx;
			}
	
			.ai12 {
				width: 28rpx;
				height: 28rpx;
			}
		}
	
	
		.qd-btn {
			width: 686rpx;
			height: 92rpx;
			background: linear-gradient(306deg, #9055FF 0%, #00EBE2 100%);
			border-radius: 52rpx 52rpx 52rpx 52rpx;
			font-weight: 500;
			font-size: 36rpx;
			color: #FFFFFF;
			text-align: center;
			line-height: 92rpx;
			margin: 0 auto;
	
		}
	}
</style>
